<?
    final class Principio_Model_PoolMapper extends Principio_Model_Company_AbstractMapper
    {
        public static function fetch($id)
        {
            try
            {
                if (intval($id) == -1)
                    return new Principio_Model_Pool();

                $model_pool = parent::fetch($id);
                return (is_null($model_pool) ? new Principio_Model_Pool() : $model_pool);
            }
            catch (Exception $ex)
            {
                return self::reportException($ex);
            };
        }


        public static function delete(Principio_Model_Company_Abstract $model_pool, $use_transaction = true)
        {
            try
            {
                if ($use_transaction)
                    self::getDBTable()->getAdapter()->beginTransaction();

                foreach ($model_pool->getCompanies() as $model_company)
                    $model_company->delete(false);

                static::delete($model_pool, false);

                if ($use_transaction)
                    self::getDBTable()->getAdapter()->commit();
            }
            catch (Exception $ex)
            {
                Principio_Model_CompanyMapper::reportException($ex);

                if ($use_transaction)
                    self::getDBTable()->getAdapter()->rollback();

                return false;
            };
        }


        public static function getCompanies(Principio_Model_Pool $model_pool)
        {
            try
            {
                $select = self::getDBTable()->select()->where("pool_id=?", $model_pool->getID());
                $companies_raw = self::getDBTable()->fetchAll($select);

                return Principio_Model_Company::makeCollection($companies_raw->toArray());
            }
            catch (Exception $ex)
            {
                return self::reportException($ex);
            };
        }


        public static function fetchAll($except_model_company = null, PrincipioLab_IComparator $IComparator = null)
        {
            return Principio_Model_Company_AbstractMapper::fetchByType(Principio_Model_Company::TYPE_POOL, $except_model_company, $IComparator);
        }
    }
?>